package com.nsl.my_youlai.Jackson;

import com.fasterxml.jackson.core.JacksonException;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
import com.nsl.my_youlai.common.base.IBaseEnum;
import enums.learn.ColorEnum;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
@Slf4j
public class ColorEnumDeserializer extends StdDeserializer<ColorEnum> {
    public ColorEnumDeserializer() {
        this(null);

    }

    protected ColorEnumDeserializer(Class<ColorEnum> vc) {
        super(vc);
    }
    @Override
    public ColorEnum deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException, JacksonException {


        //System.out.println(jsonParser.getCodec());
        JsonNode node = jsonParser.getCodec().readTree(jsonParser);

        System.out.println("label = "+node.get("label").asText());
        System.out.println("value = "+node.get("value").asText());

        return IBaseEnum.getEnumByValue(0,ColorEnum.class);
    }
}
